package MainTest;


/**
 * Created by xuyi on 2017/2/16.
 */
public class FirstAppearingOnce {

    public static void main(String[] args) {

    }

    public class Solution {

        int[] hashtable = new int[256];
        StringBuilder sb = new StringBuilder("");

        //Insert one char from stringstream
        public void Insert(char ch) {
            sb.append(ch);
            if (hashtable[ch] == 0) {
                hashtable[ch] = 1;
            } else {
                hashtable[ch]++;
            }
        }

        //return the first appearence once char in current stringstream
        public char FirstAppearingOnce() {

            String toString = sb.toString();

            char[] chars = toString.toCharArray();

            for (int i = 0; i < chars.length; i++) {
                if (hashtable[chars[i]] == 1) {
                    return chars[i];
                }
            }
            return '#';
        }
    }


}
